package com.xjscrm.common.utils;


import org.apache.tomcat.util.codec.binary.Base64;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;

public class Base64EncryptUitl {
    public static final String KEY = "sahfxiaofihjrlvbmgfnmidv";
    public static final String P_IV = "jeicd7ex";
    public static final String DES_ALGORITHM = "DESede";

    public Base64EncryptUitl() {
    }

    public static String decodeBy3DESAndBase64(String str) {
        String decoded = null;

        try {
            byte[] rawkey = KEY.getBytes();
            IvParameterSpec iv = new IvParameterSpec(P_IV.getBytes());
            DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
            SecretKeyFactory keyfactory = SecretKeyFactory.getInstance(DES_ALGORITHM);
            SecretKey deskey = keyfactory.generateSecret(keyspec);
            Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
            cipher.init(2, deskey, iv);
            byte[] clearText = cipher.doFinal(Base64.decodeBase64(str.getBytes()));
            decoded = new String(clearText);
            return decoded;
        } catch (Exception var9) {
            var9.printStackTrace();
            throw new RuntimeException("Could not decodeBy3DESAndBase64", var9);
        }
    }

    public static String encodeBy3DESAndBase64(String str) {
        String encoded = null;

        try {
            byte[] rawkey = KEY.getBytes();
            IvParameterSpec iv = new IvParameterSpec(P_IV.getBytes());
            DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
            SecretKeyFactory keyfactory = SecretKeyFactory.getInstance(DES_ALGORITHM);
            SecretKey deskey = keyfactory.generateSecret(keyspec);
            Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
            cipher.init(1, deskey, iv);
            byte[] cipherText = cipher.doFinal(str.getBytes());
            encoded = new String(Base64.encodeBase64(cipherText));
            return encoded;
        } catch (Exception var9) {
            var9.printStackTrace();
            throw new RuntimeException("Could not encodeBy3DESAndBase64", var9);
        }
    }
}
